"use strict";
cc._RF.push(module, '0caeaaqodVKDqEnEe7ohNog', 'nineSpace');
// scripts/res/nineSpace.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../engines/gameEngine");
var shouShi_database_1 = require("./shouShi_database");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var gdiLayer = /** @class */ (function (_super) {
    __extends(gdiLayer, _super);
    function gdiLayer() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.gdiShadow = null;
        _this.gdi = null;
        _this.lbTopic = null;
        _this.lbDesc = null;
        _this.lbAnswer = null;
        _this.lbAnswerPy = null;
        _this.m_maxWidth = 50;
        _this.m_minWidth = null;
        // LIFE-CYCLE CALLBACKS:
        _this.lastPos = null;
        _this.allPos = [];
        //
        _this.waitSkillId = null;
        _this.m_writeCallBack = null;
        _this.m_touchIngWidth = null;
        return _this;
    }
    gdiLayer.prototype.onLoad = function () {
        this.node.on('touchstart', this.onTouchStart.bind(this));
        this.node.on('touchmove', this.onTouchMove.bind(this));
        this.node.on('touchend', this.onTouchEnd.bind(this));
        this.node.on('touchcancel', this.onTouchCancel.bind(this));
    };
    gdiLayer.prototype.start = function () {
        this.m_minWidth = this.gdi.lineWidth;
    };
    gdiLayer.prototype.setTopic = function (ziId) {
        this.m_ziId = ziId;
        this.m_ziInfo = gameEngine_1.default.getManagers().ziMgr.getZiDiInfo(ziId);
        this.gdi.clear();
        this.gdiShadow.clear();
        if (!this.m_ziInfo) {
            console.error('#48未知错误 字不存在', ziId);
            return;
        }
        this.lbTopic.string = this.m_ziInfo.name;
        this.lbTopic.node.opacity = 255;
        this.lbAnswer.string = '';
        this.lbAnswer.node.opacity = 0;
        this.lbAnswerPy.string = '';
        this.gdi.node.opacity = 255;
        this.gdiShadow.node.opacity = 255;
    };
    gdiLayer.prototype.setAnswer = function (ziId) {
        var answer = gameEngine_1.default.getManagers().ziMgr.getZiDiInfo(ziId);
        this.lbAnswer.string = "" + answer.name;
        this.lbAnswerPy.string = "[ " + answer.py + " ]";
    };
    gdiLayer.prototype.showOver = function (answerZiId, overCallBack) {
        var _this = this;
        var answer = gameEngine_1.default.getManagers().ziMgr.getZiDiInfo(answerZiId);
        this.lbAnswer.string = answer.name;
        this.lbAnswer.node.opacity = 0;
        var showTime = 1.5;
        cc.tween(this.gdiShadow.node)
            .to(showTime * 0.5, { opacity: 0 })
            .start();
        cc.tween(this.gdi.node)
            .to(showTime * 0.5, { opacity: 0 })
            .start();
        cc.tween(this.lbTopic.node)
            .to(showTime, { opacity: 0 })
            .start();
        cc.tween(this.lbAnswer.node)
            .to(showTime, { opacity: 255 })
            .call(function () {
            _this.lbAnswerPy.string = "[ " + answer.py + " ]";
            overCallBack();
        })
            .start();
    };
    gdiLayer.prototype.clearGdi = function () {
        this.gdi.clear();
        this.gdiShadow.clear();
    };
    gdiLayer.prototype.setWriteOverFunction = function (writeCallBack) {
        this.m_writeCallBack = writeCallBack;
    };
    gdiLayer.prototype.onTouchStart = function (event) {
        console.log('onTouchstart');
        this.allPos = [];
        this.gdi.clear();
        this.gdiShadow.clear();
        //
        this.lastPos = event.touch.getLocation();
        this.allPos.push(this.lastPos);
        var _a = this.touchPosToScenePos(this.lastPos), x = _a.x, y = _a.y;
        // this.gdi.circle(x, y, this.gdi.lineWidth * 0.1);
        // this.gdi.stroke();
        this.gdi.moveTo(x, y);
        // this.gdiShadow.circle(x, y, this.gdiShadow.lineWidth * 0.01);
        // this.gdiShadow.stroke();
        this.gdiShadow.moveTo(x, y);
        this.onTouchStarted();
    };
    gdiLayer.prototype.onTouchMove = function (event) {
        this.lastPos = event.touch.getLocation();
        this.allPos.push(this.lastPos);
        var _a = this.touchPosToScenePos(this.lastPos), x = _a.x, y = _a.y;
        var pos = this.touchPosToScenePos(event.getPreviousLocation());
        // this.gdi.moveTo(x,y);
        this.gdi.moveTo(pos.x, pos.y);
        this.gdi.lineTo(x, y);
        // this.gdi.moveTo(x,y);
        this.gdi.stroke();
        this.gdiShadow.moveTo(pos.x, pos.y);
        this.gdiShadow.lineTo(x, y);
        this.gdiShadow.stroke();
        this.onTouchMoved();
    };
    gdiLayer.prototype.onTouchEnd = function (event) {
        console.log("touchEndDDDDD");
        this.onTouchOver();
    };
    gdiLayer.prototype.onTouchCancel = function (event) {
        console.log("touchCancel");
        this.onTouchOver();
    };
    gdiLayer.prototype.onTouchStarted = function () {
        // if (this.m_touchIngWidth == null) {
        //     this.m_touchIngWidth = () => {
        //         this.gdi.lineWidth = Math.min(this.gdi.lineWidth + 1, this.m_maxWidth);
        //     }
        // }
        // this.schedule(this.m_touchIngWidth, 0.3);
    };
    gdiLayer.prototype.onTouchMoved = function () {
        // this.gdi.lineWidth = Math.max(this.gdi.lineWidth - 1, this.m_minWidth);
    };
    gdiLayer.prototype.onTouchOver = function () {
        // this.unschedule(this.m_touchIngWidth);
        console.log("笔画画完");
        var skillId = shouShi_database_1.default.getCalcSkillIdOfMap(this.allPos);
        console.log(skillId, "skillId");
        //笔划信息
        var bf = gameEngine_1.default.getManagers().ziMgr.getZiBiInfo(skillId);
        console.debug('笔划信息', bf);
        //位置信息
        var posInfo = this.getPosStartEndInfo();
        //获取合成的字
        var makeZiId = gameEngine_1.default.getManagers().ziMgr.getMakeZi(this.m_ziId, bf.id, posInfo);
        console.debug('合成的字', makeZiId);
        if (makeZiId == null) {
            this.lbDesc.string = '完全不对';
        }
        else {
            if (makeZiId == 'have') {
                this.lbDesc.string = '笔划对了';
            }
            else {
                this.lbDesc.string = '你写的是:' + gameEngine_1.default.getManagers().ziMgr.getZiDiInfo(makeZiId).name;
            }
        }
        this.m_writeCallBack && this.m_writeCallBack(makeZiId);
    };
    gdiLayer.prototype.getPosStartEndInfo = function () {
        var startPos = this.touchPosToScenePos(this.allPos[0]);
        var start = gameEngine_1.default.getManagers().ziMgr.getMakePosOfVec2(startPos, this.node.getContentSize());
        console.debug('开始信息', startPos, start);
        var endPos = this.touchPosToScenePos(this.allPos[this.allPos.length - 1]);
        var end = gameEngine_1.default.getManagers().ziMgr.getMakePosOfVec2(endPos, this.node.getContentSize());
        console.debug('结束信息', endPos, end);
        return { start: start, end: end };
    };
    gdiLayer.prototype.touchPosToScenePos = function (touchPos) {
        return cc.v2(touchPos.x - this.node.parent.width / 2 - this.node.x, touchPos.y - this.node.parent.height / 2 - this.node.y);
    };
    gdiLayer.prototype.getStartEndPos = function () {
    };
    __decorate([
        property(cc.Graphics)
    ], gdiLayer.prototype, "gdiShadow", void 0);
    __decorate([
        property(cc.Graphics)
    ], gdiLayer.prototype, "gdi", void 0);
    __decorate([
        property(cc.Label)
    ], gdiLayer.prototype, "lbTopic", void 0);
    __decorate([
        property(cc.Label)
    ], gdiLayer.prototype, "lbDesc", void 0);
    __decorate([
        property(cc.Label)
    ], gdiLayer.prototype, "lbAnswer", void 0);
    __decorate([
        property({ type: cc.Label })
    ], gdiLayer.prototype, "lbAnswerPy", void 0);
    gdiLayer = __decorate([
        ccclass
    ], gdiLayer);
    return gdiLayer;
}(cc.Component));
exports.default = gdiLayer;

cc._RF.pop();